package com.cjp.controller;

import com.cjp.pojo.Result;
import com.cjp.utils.FileUploadUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
@RequestMapping("/upload")
public class FileUploadController {

    @PostMapping
    public Result<String> fileUpload(MultipartFile file) throws Exception {
        String OriginalFileName = file.getOriginalFilename();
        String filename = UUID.randomUUID() + OriginalFileName.substring(OriginalFileName.lastIndexOf("."));
        String url = FileUploadUtil.uploadFile(filename, file.getInputStream());
        return Result.success(url);
    }
}
